#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
#define DOCTEST_CONFIG_SUPER_FAST_ASSERTS
#include <doctest/doctest.h>

#include "file_opt.hpp"
#include <cassert>

#include <stdio.h>
#include <time.h>

TEST_CASE("file opt test1")
{
    FileOpt::FileStat buf;
    int result;
    char timebuf[26];
    char* filename = "D:/WMQ/repo/base/build/tests/";
    errno_t err;

    // Get data associated with "crt_stat.c":
    result = FileOpt::GetFileInfo(filename, &buf);

    // Check if statistics are valid:
    if (result != 0)
    {
        perror("Problem getting information");
        switch (errno)
        {
        case ENOENT:
            printf("File %s not found.\n", filename);
            break;
        case EINVAL:
            printf("Invalid parameter to _stat.\n");
            break;
        default:
            /* Should never be reached. */
            printf("Unexpected error in _stat.\n");
        }
    }
    else
    {
        if (S_ISREG(buf.st_mode))
        {
            printf("S_ISREG\n");
        }

        if (S_ISDIR(buf.st_mode))
        {
            printf("S_ISDIR\n");
        }
        if (S_IWRITE & buf.st_mode)
        {
            printf("S_IWRITE\n");
        }
        if (S_IEXEC & buf.st_mode)
        {
            printf("S_IEXEC\n");
        }
        // Output some of the statistics:
        printf("File size     : %lld\n", buf.st_size);
        err = ctime_s(timebuf, 26, &buf.st_mtime);
        if (err)
        {
            printf("Invalid arguments to ctime_s.");
        }
        else
        {
            printf("Time modified : %s", timebuf);
        }
    }
}

TEST_CASE("file opt test2")
{
    std::string df = "/fdfd/fdd/";
    std::string dir;
    std::string file_name;
    std::string file_ext;
    FileOpt::SplitPath(df, dir, file_name, file_ext);
    std::cout << "dir:" << dir << " "
              << "file_name:" << file_name << " "
              << "file_ext:" << file_ext << std::endl;
    std::string real_path;
    const char* path = nullptr;
    if (0 == FileOpt::RealPath(path, real_path))
    {
        std::cout << "real_path:" << real_path << std::endl;
    }

    std::string cwd;
    FileOpt::GetCwd(cwd);
    std::cout << "cwd:" << cwd << std::endl;

    // if (0 == FileOpt::CreateDir("fdfdsd/"))
    // {
    //     std::cout << "FileOpt::CreateDir success" << std::endl;
    // }
    // else
    // {
    //     std::cout << "FileOpt::CreateDir error:" << errno << std::endl;
    // }

    // if (0 == FileOpt::CreateMultiDir("fdfdsd/trttr/hfghf/"))
    // {
    //     std::cout << "FileOpt::CreateMultiDir success" << std::endl;
    // }
    // else
    // {
    //     std::cout << "FileOpt::CreateMultiDir error:" << errno << std::endl;
    // }
}
